#ifndef _CONTROL_SYSTEM_H_
#define _CONTROL_SYSTEM_H_

#include "../LogicSystem.h"
#include "menu/GUI.h"
#include "../game/GameConf.h"
#include "../input/InputSystem.h"

//Forward declaration to reduce dependencies
class GameControl;

/**	The system that controls the 'control thread'
	All main menu/GUI stuff is handled here as well as dispatching instances of GameControl
	The main loop should create an instance and loop over this while isOk() is true
*/
class ControlSystem: public LogicSystem, public InputInterface
{
	GUI gui;						//The main menu gui
	CmdLineArgs* args;				//Instance of command line args to pass around as needed
	GameControl* gameInstance;		//Instance of the game to work with
	
	string game_config_file;			//Filename of the config file to load a game with
	
	//This is a singleton so only we can create instances of ourselves
	ControlSystem();
	ControlSystem(const ControlSystem&):LogicSystem(), InputInterface(), gui(), args(NULL), gameInstance(NULL) {};
	ControlSystem& operator = (const ControlSystem&) { return *this; };

public:
	static inline ControlSystem& Instance()  {	static ControlSystem cs; return cs;	}
	
	~ControlSystem();

	/**	Whether it's ok to continue execution of the system
		If this returns false, the system desires to terminate the program
	*/
	bool isOk();
	void setOk(bool b);					//Set whether it's ok to continue execution of the system

	void onWindowResize(float, float);		//Called whenever draw notices that the window size changed

	/** Creates an instance of a game with the desired configuration */
	void createGame(const GameConf&);
	
	/** Destroys the currently running game */
	void destroyGame();
	
	/** Exits the application. This should be called whenever we desire to terminate */
	void exitApp();
	
	/** When we want to switch the main gui to the frame with the name */
	void changeGUIto(std::string&);
	
	/** Turns the gui off */
	void disableGUI();
	
	void update(long dt = 0);
	bool init(const CmdLineArgs& args);
	void kill();
	void terminate();
		
	void onMouseButtonDown(KEY_TYPE, int, int);
	void onMouseButtonUp(KEY_TYPE , int, int);
	
	void onKeyDown(KEY_TYPE);
	void onKeyUp(KEY_TYPE);
	
	void onMouseMove(int, int);
	
	void onMouseWheelUp() {};
	void onMouseWheelDown() {};
};

#endif
